package com.example.lizhixin.object_three_team.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.lizhixin.object_three_team.R;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class GameRcdAdapter extends XRecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final static int BU1 = 0;
    private final static int BU2 = 1;
    private   final static int BU3 = 2;
    private List<String> list = new ArrayList<>();
    public void referch(List<String> list){
        this.list = list;
    }
    @Override
    public int getItemViewType(int position) {
        switch (position){
            case 0:
                return BU1;
            case 1:
                return BU2;
            case 2:
                return BU3;
        }
        return 0;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if (i == BU1){
            View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.game_banner, viewGroup, false);
            return new Mybanner(inflate);
        }else if (i == BU2){
            View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.game_new_day, viewGroup, false);
            return new MyNewday(inflate);
        }else if (i == BU3){
            View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.game_img, viewGroup, false);
            return new MyRcdimg(inflate);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        Log.d("img",list.get(0));
//            if (viewHolder instanceof Mybanner){
//                Mybanner mybanner = (Mybanner) viewHolder;
//                mybanner.banner.setImageLoader(new MyBanner())
//                .setImages(list)
//                .setDelayTime(1000)
//                .start();
//            }
        switch (getItemViewType(i)){
            case 0:
                ((Mybanner)viewHolder).banner.setImageLoader(new ImageLoader() {
                    @Override
                    public void displayImage(Context context, Object path, ImageView imageView) {
                        Glide.with(context).load(""+path).into(imageView);

                    }
                }).setDelayTime(1000)
                        .setImages(list).start();
                break;
        }
    }

    @Override
    public int getItemCount() {
        return 3;
    }

    class Mybanner extends XRecyclerView.ViewHolder{
        Banner banner;

        public Mybanner(@NonNull View itemView) {
            super(itemView);
            banner = itemView.findViewById(R.id.Rcd_ber);
        }
    }
    class MyNewday extends XRecyclerView.ViewHolder{

        public MyNewday(@NonNull View itemView) {
            super(itemView);
        }
    }
    class MyRcdimg extends XRecyclerView.ViewHolder{

        public MyRcdimg(@NonNull View itemView) {
            super(itemView);
        }
    }
}
